package com.hopu.v1.controller.admin.question;

import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.question.QuestionsBanks;
import com.hopu.v1.service.admin.question.QuestionsBanksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: YwaiX
 * @Version: 1.0
 * @Date: Created in 2024-09-26 14:29:44
 * @Description: 题库
 */

@RestController
@RequestMapping("/api/v1/admin/question/banks")
public class QuestionsBanksController {
    
    @Autowired
    private QuestionsBanksService questionsBanksService;
    
    /**
     * 条件获取题库列表
     *
     * @param sid
     * @return
     */
    @GetMapping
    public R getQuestionsBankList(Integer page, Integer size, Integer sid ,String name,Integer status) {
        System.out.println(status);
        PageData<QuestionsBanks> questionsBankList = questionsBanksService.getQuestionsBankList(page, size, sid,name,status);
        return R.ok("获取成功", questionsBankList);
    }
    
    /**
     * 添加题库
     *
     * @param questionsBanks
     * @return
     */
    @PostMapping
    public R insertQuestionBank(@RequestBody QuestionsBanks questionsBanks) {
        questionsBanksService.save(questionsBanks);
        return R.ok("添加成功");
    }
    
    /**
     * 修改题库
     *
     * @param questionsBanks
     * @return
     */
    @PutMapping
    public R updateQuestionBank(@RequestBody QuestionsBanks questionsBanks) {
        questionsBanks.setUpdateTime(LocalDateTime.now());
        questionsBanks.setStatus(0);
        questionsBanksService.updateById(questionsBanks);
        return R.ok("修改成功");
    }
    
    /**
     * 删除题库
     *
     * @param id
     * @return
     */
    @DeleteMapping
    public R deleteQuestionBank(Integer id) {
        questionsBanksService.removeById(id);
        return R.ok("删除成功");
    }
}
